package com.njwb.day18.factory;

public class Custom implements Runnable{
private Produce produce;

    public Custom(Produce produce) {
        this.produce = produce;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (produce) {
                if (produce.count == 0) {
                    try {
                        produce.wait(); // 等待生产
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    System.out.println("消费者消费了: " + produce.name + " (" + produce.skin + ")");
                    produce.count = 0;
                    produce.notifyAll(); // 通知生产者生产
                }
            }
        }
    }
}
